
from datetime import datetime
from typing import Union, Any, Optional, List

from pydantic import BaseModel, EmailStr, Field
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from sqlalchemy.schema import Sequence

#from app.common.database import Base
from app.models.base import TableBase


class Merchant(TableBase):
    """商户表"""
    __tablename__ = "t_merchant"

    id = Column(Integer, primary_key=True, index=True)
    merc_no = Column(String(24), unique=True, index=True, comment='商户编号')
    merc_name = Column(String(40), comment='创建人')
    factor_no = Column(String(24), comment='所属代理编号')
    cert_type = Column(String(2), comment='证件类型')
    cert_no = Column(String(30), comment='证件号')
    status = Column(Integer, comment='状态')
    contact_person = Column(String(32), comment='联系人')
    email = Column(String(40), comment='邮箱')
    address = Column(String(120), comment='地址')

class MerchantFee(TableBase):
    """商户费率表"""
    __tablename__ = "t_merchant_fee_rate"

    id = Column(Integer, primary_key=True, index=True)
    merc_no = Column(String(40), unique=True, index=True, comment='商户编号')
    product_code = Column(String(32), comment='产品编码')
    product_name = Column(String(40), comment='产品名称')
    pay_channel_code = Column(String(32), comment='通道编码')
    fee_mode = Column(Integer, comment='计费模式 1.单笔固定 2.百分比')
    fee_value = Column(Integer, comment='费率值')
    status = Column(Integer, comment='状态')

    __table_args__ = (
        UniqueConstraint('merc_no', 'product_code', 'pay_channel_code'),
    )


class MerchantKey(TableBase):
    """商户密钥表"""
    __tablename__ = "t_merchant_key"

    id = Column(Integer, primary_key=True, index=True)
    merc_no = Column(String(40), unique=True, index=True, comment='商户编号')
    algorithm = Column(Integer, comment='加密算法')
    status = Column(Integer, comment='状态')
    secret_key = Column(String(128), comment='安全密钥')
    pri_key = Column(Text, comment='私钥')
    pub_key = Column(Text, comment='公钥')
    extras = Column(String(128), comment='额外配置')

